package com.jeff.controller;

import com.jeff.common.mConst;
import com.jeff.po.FormTh;
import com.jeff.service.FormThService;
import com.jeff.util.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("formTh")
public class FormThController {

    @Autowired
    public FormThService formThService;

    @RequestMapping("add")
    @ResponseBody
    public ResultMap add(HttpServletRequest request, FormTh formTh) {
        ResultMap rm = new ResultMap();
        try {
            formTh.setState(mConst.STATE_T);
            formThService.add(formTh);
            rm.success().info("增加成功");
        } catch (Exception e) {
            e.printStackTrace();
            rm.fail().info("增加失败");
        }
        return rm;
    }

    @RequestMapping("list")
    @ResponseBody
    public ResultMap list() {
        ResultMap rm = new ResultMap();
        try {
            FormTh formTh = new FormTh();
            formTh.setId(null);
            formTh.setState(mConst.STATE_T);
            List<FormTh> list = formThService.list(formTh);
            rm.success().data(list);
        } catch (Exception e) {
            e.printStackTrace();
            rm.fail().info("fail");
        }
        return rm;
    }


    @RequestMapping("page")
    @ResponseBody
    public ResultMap page(FormTh formTh) {
        ResultMap rm = new ResultMap();
        try {
            formTh.setId(null);
            formTh.setState(mConst.STATE_T);
            rm.success().page(formThService.findByPage(formTh));
        } catch (Exception e) {
            e.printStackTrace();
            rm.fail().info("fail");
        }
        return rm;
    }


    @RequestMapping("update")
    @ResponseBody
    public ResultMap update(FormTh formTh) {
        ResultMap rm = new ResultMap();
        try {
            formThService.update(formTh);
            rm.success().info("修改成功");
        } catch (Exception e) {
            rm.fail().info("修改失败");
        }
        return rm;
    }

    @RequestMapping("remove")
    @ResponseBody
    public ResultMap remove(FormTh formTh) {
        ResultMap rm = new ResultMap();
        try {
            formTh.setState(mConst.STATE_F);
            formThService.update(formTh);
            rm.success().info("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            rm.fail().info("删除失败");
        }
        return rm;
    }


}
